package com.dragon.flow.enm.flowable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @title: 流程实例状态枚举
 * @author: bruce.liu
 * @since: 2024/9/8 22:30
 */
public enum ProcessInstanceStatusEnum {
    DRAFT("draft", "草稿"), REVOKE("revoke", "撤回"), APPLYING("applying", "审批中"),  ZZ("zz", "终止"), END("end", "结束");
    private String code;
    private String name;

    ProcessInstanceStatusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (ProcessInstanceStatusEnum e : ProcessInstanceStatusEnum.values()) {
            list.add(new HashMap<String, Object>() {{
                put("id", e.code);
                put("text", e.name);
            }});
        }
        return list;
    }

    public static ProcessInstanceStatusEnum getByCode(String code) {
        for (ProcessInstanceStatusEnum e : ProcessInstanceStatusEnum.values()) {
            if (e.code.equals(code)) {
                return e;
            }
        }
        return null;
    }
}
